//
//  GZApplyConnectListView.swift
//  GLUZ
//
//  Created by lemon on 2025/3/11.
//

import UIKit

class GZApplyConnectListView: UIView {
    
    var host: ZegoUIKitUser? {
        didSet {
            guard let host = host else {
                return
            }
            self.setHeadUserName(host.userName ?? "")
        }
    }
    lazy var closeButton: UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(closeButtonClick), for: .touchUpInside)
        button.setImage(UIImage(named: "关闭小"), for: .normal)
        return button
    }()
    lazy var roleLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 11, weight: .semibold)
        label.textColor = UIColor.colorWithHexString("#FFBB00")
        return label
    }()
    lazy var headImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "麦位")
        imageView.contentMode = .scaleAspectFit
        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 26
        return imageView
    }()
    lazy var headNameLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 12, weight: .semibold)
        label.textColor = UIColor.colorWithHexString("#FFBB00")
        return label
    }()
    lazy var countLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 6, weight: .semibold)
        label.textColor = UIColor.colorWithHexString("#0E0E0E")
        label.backgroundColor = UIColor.colorWithHexString("#D9D9D9")
        label.layer.cornerRadius = UIkitLiveAdaptLandscapeWidth(6)
        label.layer.masksToBounds = true
        return label
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.layer.cornerRadius = UIkitLiveAdaptLandscapeWidth(8)
        self.layer.masksToBounds = true
        self.backgroundColor = UIColor.colorWithHexString("#000000").withAlphaComponent(0.3)
        self.addSubview(self.closeButton)
        self.addSubview(self.roleLabel)
        self.addSubview(self.headImageView)
        self.addSubview(self.headNameLabel)
        self.headImageView.addSubview(self.countLabel)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.setupLayout()
    }
    
    func setupLayout() {
        self.closeButton.frame = CGRect(x: self.frame.size.width - 15, y: 0, width: 15, height: 15)
        self.roleLabel.frame = CGRect(x: 15, y: 0, width: self.frame.size.width - 30, height: 15)
        self.headImageView.frame = CGRect(x: 19, y: 17, width: 52, height: 52)
        self.headNameLabel.frame = CGRect(x: 0, y: self.frame.size.height - 18, width: self.frame.size.width - 10, height: 16)
        self.headNameLabel.frame = CGRect(x: self.headImageView.frame.size.width - 3, y: 3, width: 12, height: 12)
    }
    
    private func setHeadUserName(_ userName: String) {
//        if userName.count > 0 {
//            let firstStr: String = String(userName[userName.startIndex])
//        }
    }
    
    @objc func closeButtonClick() {

        
    }
}


